package sse.ustc.cc.custom;

import sse.ustc.cc.activity.R;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
/**
 * 课程时间选择dialog
 * @author xuhao
 *
 */
public class TimeChooseDialog extends Dialog{

	private TextView start_timeplay = null;//课程开始时间
	private TextView end_timeplay = null;//课程结束时间
	
	private TimePicker starttime = null;//选择课程开始时间
	private TimePicker endtime = null;//选择课程开始时间
	/** 设置默认上课时间*/
	private String starthour = "08";
	private String startMinute = "00";
	private String endHour = "08";
	private String endMinute = "00";
	
	Context context;
	public TimeChooseDialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	public TimeChooseDialog(Context context, int theme){
        super(context, theme);
        this.context = context;
    }
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //点击对话框外禁止取消窗口
        setCanceledOnTouchOutside(false);
        setContentView(R.layout.timechoose);
        
        start_timeplay = (TextView)findViewById(R.id.start_timeplay);
        end_timeplay = (TextView)findViewById(R.id.end_timeplay);
        //设置默认显示时间
        start_timeplay.setText(getStarthour() + ":" + getStartMinute());
        end_timeplay.setText(getEndHour() + ":" + getEndMinute());
        
        starttime = (TimePicker)findViewById(R.id.timestart);
        endtime = (TimePicker)findViewById(R.id.timeend);
        //设置时间选择为24小时
        starttime.setIs24HourView(true);
        endtime.setIs24HourView(true);
        //设置默认显示时间
        starttime.setCurrentHour(8);
        starttime.setCurrentMinute(0);
        endtime.setCurrentHour(8);
        endtime.setCurrentMinute(0);
        
        //选择开始时间
        starttime.setOnTimeChangedListener(new OnTimeChangedListener() {
			
			@Override
			public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
				// TODO Auto-generated method stub
				
				setStarthour(hourOfDay);  
				setStartMinute(minute);
				start_timeplay.setText(getStarthour() + ":" + getStartMinute());
			}
		});
      //选择结束时间
        endtime.setOnTimeChangedListener(new OnTimeChangedListener() {
			
			@Override
			public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
				// TODO Auto-generated method stub
				
				setEndHour(hourOfDay);
				setEndMinute(minute);
				end_timeplay.setText(getEndHour() + ":" + getEndMinute());
			}
		});
        
    }
	public String getStarthour() {
		return starthour;
	}
	public void setStarthour(int starthour) {
		if(starthour < 10){
			this.starthour = "0" + starthour;
		}else{
			this.starthour = starthour + "";
		}
		
	}
	public String getStartMinute() {
		return startMinute;
	}
	public void setStartMinute(int startMinute) {
		if(startMinute < 10){
			this.startMinute = "0" + startMinute;
		}else{
			this.startMinute = startMinute + "";
		}
	}
	public String getEndHour() {
		return endHour;
	}
	public void setEndHour(int endHour) {
		if(endHour < 10){
			this.endHour = "0" + endHour;
		}else{
			this.endHour = endHour + "";
		}
	}
	public String getEndMinute() {
		return endMinute;
	}
	public void setEndMinute(int endMinute) {
		if(endMinute < 10){
			this.endMinute = "0" + endMinute;
		}else{
			this.endMinute = endMinute + "";
		}
	}
}
